<template>
  <detail-dialog modal   showReset  :title="title" :show.sync="show" @reset="resetForm" @update:show="updateShow" :top="5" @save="save">
    <el-form :model="editOrderInfo" label-width="140px" :rules="rules" ref="orderInfoForm">
      <el-form-item label="采购金额" prop="purchaseAmount">
        <el-input
          style="width: 90%"
          v-model="editOrderInfo.purchaseAmount"
          placeholder="采购金额" clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="采购日期" prop="purchaseDate">
        <el-date-picker
          style="width: 90%"
          v-model="editOrderInfo.purchaseDate"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date" clearable
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          style="width: 90%"
          type="textarea"
          v-model="editOrderInfo.remark"
          placeholder="备注"
        ></el-input>
      </el-form-item>
    </el-form>
  </detail-dialog>
</template>
<script>
import DetailDialog from '@/components/DetailDialog'
import Mixins from '../../mixins'
export default {
  name: 'order_base',
  props: {
    title: {type: String, default: '编辑基本信息'},
    visible: {
      type: Boolean,
      default: false
    },
    param: {type: Object,
      default: () => {
        return {}
      }}
  },
  components: { DetailDialog },
  mixins: [Mixins],
  created () {
  },
  watch: {
    param: {
      handler (nVal, oVal) {
        this.editOrderInfo = {...nVal}
      },
      deep: true,
      immediate: true
    },
    show (nVal) {
      this.$emit('update:visible', nVal)
    },
    visible (nVal) {
      this.show = nVal
    }
  },
  data () {
    return {
      editOrderInfo: {},
      show: this.visible,
      rules: {
        purchaseAmount: [{ required: true, message: '不能为空', trigger: 'blur' }],
        purchaseDate: [{ required: true, message: '不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    save () {
      this.$refs.orderInfoForm.validate(valid => {
        if (valid) {
          const params = {}
          params.purchaseNo = this.editOrderInfo.purchaseNo
          params.purchaseAmount = this.editOrderInfo.purchaseAmount
          params.purchaseDate = this.editOrderInfo.purchaseDate
          params.remark = this.editOrderInfo.remark
          this.requestOption('updateOrder', params, res => {
            this.updateShow(false)
            this.$emit('saveAfter', this.editOrderInfo.purchaseNo)
          })
        }
      })
    },
    updateShow (val) {
      this.show = val
    },
    resetForm () {
      this.$refs.orderInfoForm.resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
